<template>
    <div class="div">
        <div class="banner" @mouseleave="(cateId = null)">
            <div class="cate">
                <ul class="ulOne">
                    <li v-for="(item, index) in cate" :key="item.id" @mouseenter="(key = index, cateId = item.id)"
                        :class="{ des: cateId == item.id }">
                        <router-link to="/" class="linkOne">{{ item.name }}</router-link>
                        <template v-if="item.children">
                            <router-link to="/" class="linkOne" v-for="it in item.children" :key="it.id">{{
                                    it.name
                            }}</router-link>
                        </template>
                        <template v-if="!item.children">
                            <SkeleonView width="40px" height="15px" bj="red"></SkeleonView>
                            <SkeleonView width="40px" height="15px"></SkeleonView>
                        </template>
                    </li>
                </ul>
                <div class="showCate">
                    <h4>{{ fot.keys == 'cate' ? '分类推荐' : '品牌推荐' }}<small>根据您的浏览或购买记录推荐</small></h4>
                    <ul class="fot-box" v-if="fot.keys == 'cate'">
                        <li v-for="item in fot.goods" :key="item.id">
                            <router-link to="/" class="li-item">
                                <img :src="item.picture" alt="">
                                <div class="info">
                                    <p class="name ellipsis-2">{{ item.name }}</p>
                                    <p class="desc ellipsis">{{ item.desc }}</p>
                                    <p class="price"><i>¥</i>{{ item.price }}</p>
                                </div>
                            </router-link>
                        </li>
                    </ul>
                    <ul class="fot-box" v-else>
                        <li v-for="item in fot.goods" :key="item.id">
                            <router-link to="/" class="li-item">
                                <img :src="item.logo" alt="">
                                <div class="info">
                                    <p class="desc ellipsis">{{ item.place }}</p>
                                    <p class="name ellipsis-2">{{ item.name }}</p>
                                    <p class="desc">{{ item.desc }}</p>
                                </div>
                            </router-link>
                        </li>
                    </ul>
                </div>
            </div>
            <swiper-header-vue></swiper-header-vue>
        </div>
    </div>

</template>

<script>
import { getBrand } from '@/Api/homeapi'
import SwiperHeaderVue from './SwiperHeader.vue'
export default {
    components: { SwiperHeaderVue },
    data() {
        return {
            key: 0,
            good: [],
            cateId: null
        }
    },
    mounted() {
        this.getList()
    },
    computed: {
        cate() {
            let obj = {
                id: '123123',
                name: '品牌',
                children: [{ id: '123123', name: '品牌推荐' }]
            }
            const list = this.$store.state.list.map(item => {
                return {
                    id: item.id,
                    name: item.name,
                    children: item.children && item.children.slice(0, 2)
                }
            })
            list.push(obj)
            return list
        },
        fot() {
            let obj = {
                keys: '',
                goods: []
            }
            if (this.key < 9) {
                obj.keys = 'cate'
                obj.goods = this.$store.state.list[this.key].goods
            } else {
                obj.keys = 'brand'
                obj.goods = this.good
            }
            // console.log(this.key);
            return obj
        }
    },
    methods: {
        async getList() {
            let { data: res } = await getBrand(6)
            // console.log(res);
            this.good = res.result
        }
    }
}
</script>


<style lang="scss" scoped>
@import '@/assets/css/variables.scss';



.div {
    width: 1240px;
    margin: auto;
    // background: orange;
}

.des {
    background: $xtxColor ;
}

.banner {
    width: 100%;
    height: 500px;
    display: flex;
    justify-content: space-between;
    position: relative;

    .cate {
        position: absolute;
        z-index: 5;
        &:hover {
            .showCate {
                display: block;
            }
        }

        .ulOne {
            width: 250px;
            height: 100%;
            background: rgba(0, 0, 0, 0.8);
            display: flex;
            flex-direction: column;
            justify-content: space-between;
            align-items: center;


            li {
                width: 100%;
                height: 50px;
                text-align: center;
                line-height: 50px;

                .linkOne {
                    text-decoration: none;
                    color: white;
                    margin-left: 5px;
                    box-sizing: border-box;
                }
            }

            li:hover {
                background: $xtxColor ;
            }
        }

        .showCate {
            width: 990px;
            height: 500px;
            background: rgba(255, 255, 255, 0.8);
            position: absolute;
            left: 250px;
            top: 0;
            display: none;
            padding: 0 15px;

            h4 {
                font-size: 20px;
                font-weight: normal;
                line-height: 80px;
            }

            .fot-box {
                display: flex;
                flex-wrap: wrap;

                li {
                    width: 310px;
                    height: 120px;
                    margin-right: 15px;
                    margin-bottom: 15px;
                    border: 1px solid #eee;
                    border-radius: 4px;
                    background: #fff;

                    &:nth-child(3n) {
                        margin-right: 0;
                    }

                    .li-item {
                        width: 100%;
                        height: 100%;
                        display: flex;
                        justify-content: space-around;
                        align-items: center;
                        text-decoration: none;

                        &:hover {
                            background: #e3f9f4;
                        }

                        img {
                            width: 95px;
                            height: 95px;
                        }


                        .info {
                            padding-left: 10px;
                            line-height: 24px;
                            width: 190px;

                            .name {
                                font-size: 16px;
                                color: #666;
                            }

                            .desc {
                                color: #999;
                                overflow: hidden;
                                text-overflow: ellipsis;
                                white-space: nowrap;
                            }

                            .price {
                                font-size: 22px;
                                color: $priceColor;

                                i {
                                    font-size: 16px;
                                }
                            }
                        }
                    }
                }
            }
        }
    }



}
</style>